package handlers

import (
	"github.com/gin-gonic/gin"
	"repo-master2/models"
)

func AddRepo(c *gin.Context) {
	repo_name := c.PostForm("repo_name")
	address := c.PostForm("address")
	if repo_name == "" || address == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "数据不能为空",
		})
		return
	}

	repo := models.Repo{
		RepoName: repo_name,
		Address:  address,
	}

	err := models.DB.Create(&repo).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
